home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / libwww2 / HTAssoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  1.7 KB  |  81 lines

  1.  
  2. /* MODULE                            HTAssoc.c
  3. **        ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS.
  4. **        NAMES NOT CASE SENSITIVE, AND ONLY COMMON LENGTH
  5. **        IS CHECKED (allows abbreviations; well, length is
  6. **        taken from lookup-up name, so if table contains
  7. **        a shorter abbrev it is not found).
  8. ** AUTHORS:
  9. **    AL    Ari Luotonen    luotonen@dxcern.cern.ch
  10. **
  11. ** HISTORY:
  12. **
  13. **
  14. ** BUGS:
  15. **
  16. **
  17. */
  18.  
  19.  
  20. #include <string.h>
  21.  
  22. #include "HTAAUtil.h"
  23. #include "HTAssoc.h"
  24. #include "HTString.h"
  25.  
  26.  
  27. PUBLIC HTAssocList *HTAssocList_new NOARGS
  28. {
  29.     return HTList_new();
  30. }
  31.  
  32.  
  33. PUBLIC void HTAssocList_delete ARGS1(HTAssocList *, alist)
  34. {
  35.     if (alist) {
  36.     HTAssocList *cur = alist;
  37.     HTAssoc *assoc;
  38.     while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
  39.         if (assoc->name) free(assoc->name);
  40.         if (assoc->value) free(assoc->value);
  41.         free(assoc);
  42.     }
  43.     HTList_delete(alist);
  44.     }
  45. }
  46.  
  47.  
  48. PUBLIC void HTAssocList_add ARGS3(HTAssocList *,    alist,
  49.                   CONST char *,        name,
  50.                   CONST char *,        value)
  51. {
  52.     HTAssoc *assoc;
  53.  
  54.     if (alist) {
  55.     if (!(assoc = (HTAssoc*)malloc(sizeof(HTAssoc))))
  56.         outofmem(__FILE__, "HTAssoc_add");
  57.     assoc->name = NULL;
  58.     assoc->value = NULL;
  59.  
  60.     if (name) StrAllocCopy(assoc->name, name);
  61.     if (value) StrAllocCopy(assoc->value, value);
  62.     HTList_addObject(alist, (void*)assoc);
  63.     }
  64.     else if (TRACE) fprintf(stderr, "HTAssoc_add: ERROR: assoc list NULL!!\n");
  65. }
  66.  
  67.  
  68. PUBLIC char *HTAssocList_lookup ARGS2(HTAssocList *,    alist,
  69.                       CONST char *,    name)
  70. {
  71.     HTAssocList *cur = alist;
  72.     HTAssoc *assoc;
  73.  
  74.     while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
  75.     if (!strncasecomp(assoc->name, name, strlen(name)))
  76.         return assoc->value;
  77.     }
  78.     return NULL;
  79. }
  80.  
  81.